//
//  HMEmoticonPageView.swift
//  CZBKWB31
//
//  Created by Linkon Y on 16/8/18.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
// cell 可重用标示符
private let HMEmoticonPageViewId = "HMEmoticonPageViewId"
class HMEmoticonPageView: UICollectionView {
   
    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout:UICollectionViewFlowLayout())
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

     // MARK: - 设置视图
    private func setupUI(){
    //设置代理
        registerClass(HMEmoticonPageViewCell.self, forCellWithReuseIdentifier: HMEmoticonPageViewId)
        dataSource = self

        
    }
    override func layoutSubviews(){
        super.layoutSubviews()
        //设置layout
        let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
        //设置item
        layout.itemSize = self.frame.size
        //设置水平垂直
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 0
        //滚动方向
        layout.scrollDirection = .Horizontal
        
    }
   
}
extension HMEmoticonPageView:UICollectionViewDataSource{
    
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return HMEmoticonTool.sharedTools.allEmoticons.count
    }

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return HMEmoticonTool.sharedTools.allEmoticons[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(HMEmoticonPageViewId, forIndexPath: indexPath) as! HMEmoticonPageViewCell
        
        cell.indexPath = indexPath
        //赋值
        cell.emoticons = HMEmoticonTool.sharedTools.allEmoticons[indexPath.section][indexPath.item]
        return cell
        
    }

   

}
